package com.zyao89.view.zloading;


import com.zyao89.view.zloading.text.TextBuilder;
import ohos.agp.components.AttrSet;
import ohos.agp.components.DependentLayout;
import ohos.agp.utils.TextTool;
import ohos.app.Context;

/**
 * Created by zyao89 on 2017/3/19.
 * Contact me at 305161066@qq.com or zyao89@gmail.com
 * For more projects: https://github.com/zyao89
 * My Blog: http://zyao89.me
 */
public class ZLoadingTextView extends ZLoadingView {
    private String mText = "Zyao89";

    public ZLoadingTextView(Context context) {
        this(context, null);
    }

    public ZLoadingTextView(Context context, AttrSet attrs) {
        super(context, attrs);
    }

    public ZLoadingTextView(Context context, AttrSet attrs, String defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    @Override
    @Deprecated
    public void setLoadingBuilder(Z_TYPE builder) {
        super.setLoadingBuilder(Z_TYPE.TEXT);
    }

    public void setText(String text) {
        this.mText = text;
        if (mZLoadingBuilder instanceof TextBuilder) {
            ((TextBuilder) mZLoadingBuilder).setText(mText);
        }
    }

    private void init(Context context, AttrSet attrs, String defStyleAttr) {
        super.setLoadingBuilder(Z_TYPE.TEXT, DependentLayout.LayoutConfig.MATCH_CONTENT);
        try {
            String text = attrs.getAttr("z_text").get().getStringValue();
            if (!TextTool.isNullOrEmpty(text)) {
                this.mText = text;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
